﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent

Partial Class rtransstatus
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Session("StaffId") Is Nothing Then
            Response.Redirect("Default.aspx")
        ElseIf Session.Item("StaffType").ToString = "2" Then
            Response.Redirect("Default.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
            lblStaffType.Text = Session("StaffType").ToString
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            If Not Session("Tid").ToString Is Nothing Then
                lblTransUID.Text = Session("Tid").ToString
                'Me.Session.Remove("Tid")
                LoadTransInfo()
            Else
                Response.Redirect("TransList.aspx")
            End If
        End If
    End Sub

    Private Sub LoadTransInfo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, t.OpenFileRef, pt.Type, p.LASF, p.BUSF, " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', " & _
                                "j.Project, L.Name as Lister, L.Initial as ListerInitial, t.ListDate, t.TransactDate, t.TransactRemark, t.TransListType, " & _
                                "t.CoBrokeId, c.Name as CoBrokeName, c.AgencyName as CoBrokeAgencyName, c.Phone as CoBrokePhone, " & _
                                "t.CoBroke, c.Mobile as CobrokeMobile, c.Fax as CobrokeFax, c.Email as cobrokeEmail, " & _
                                "t.MonthlyRental, t.Requisition, t.AgencyFee, t.GST, t.GSTPaidBy, t.ListingFee, t.LandlordTAFee, " & _
                                "t.DisbursementFee, t.LandlordReferralAmount, t.LandlordReferralAmtSum, t.TenantReferralAmount, " & _
                                "t.TenantReferralAmtSum, t.TenantReferral, t.LandlordReferral, t.TenantTAFee, t.Deposit, t.DepositMonth, " & _
                                "t.Advance, t.AdvanceMonth, t.WaterElectric, t.Tel, t.SignDate, t.SignRemark, t.SignComplete, t.CollectDate, " & _
                                "t.Collectamt, t.CollectRemark, t.CollectComplete, t.UndoDate, t.UndoRemark, t.UndoAmt, t.GrossAmount, " & _
                                "t.TotalTA, t.TotalAgencyFee, t.StampDuty, t.ListerAmt, t.ReferralAmt, t.GovAmt, k.Name as Transactor, k.Initial as TransactorInitial, " & _
                                "t.CommencementDate, t.RentFreePeriod, t.RentFreePeriodType, t.TerminationClause, " & _
                                "ss.Name as SignCompleteBy, ss.Initial as SignCompleteByInitial, sc.Name as CollectCompleteBy, sc.Initial as CollectCompleteByInitial, us.Name as UndoStaff, us.Initial as UndoStaffInitial, t.TransactorId, t.ListerId, " & _
                                "t.SignCompleteDate, t.CollectCompleteDate, L.ListingPercent " & _
                                "FROM AW_RentTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId " & _
                                "LEFT JOIN AW_Staff k on t.TransactorId = k.StaffId " & _
                                "LEFT JOIN AW_CoBroke c on t.CoBrokeId = c.CoBrokeId LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId LEFT OUTER JOIN AW_PropertyType pt ON p.PropertyTypeId = pt.TypeId " & _
                                "LEFT OUTER JOIN AW_Staff ss ON t.SignCompleteBy = ss.staffId LEFT OUTER JOIN AW_Staff sc ON t.CollectCompleteBy = sc.StaffId " & _
                                "LEFT OUTER JOIN AW_Staff us ON t.UndoBy = us.StaffId WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        For Each row As Data.DataRow In TempDT.Rows
            If row.Item("OpenfileRef").ToString = "" Then
                Session.Add("failed", "Please complete the information before you update the status!")
                Response.Redirect("Translist.aspx", False)
            Else
                lblPropertyUID.Text = row.Item("PropertyId").ToString
                lblAddress.Text = row.Item("Address").ToString
                If row.Item("Project").ToString = "" Then
                    TRProject.Visible = False
                Else
                    TRProject.Visible = True
                    lblProject.Text = row.Item("Project").ToString
                End If
                lblPropertyType.Text = row.Item("Type").ToString
                lblLASQFT.Text = String.Format("{0:#,##0.00}", row.Item("LASF"))
                lblBUSQFT.Text = String.Format("{0:#,##0.00}", row.Item("BUSF"))
                Select Case row.Item("TransListType").ToString
                    Case "1"
                        lblTransType.Text = "RR"
                    Case "2"
                        lblTransType.Text = "RC"
                    Case "3"
                        lblTransType.Text = "RL"
                    Case "4"
                        lblTransType.Text = "RI"
                End Select
                If row.Item("CoBroke").ToString = "1" Then
                    CoBroke.Visible = True
                    lblhidCoBrokeId.Text = row.Item("CoBrokeId").ToString
                    lblCoBroke.Text = row.Item("CoBrokeName").ToString
                    lblhidCoBrokeAgencyName.Text = row.Item("CoBrokeAgencyName").ToString
                    lblhidCoBrokePhone.Text = row.Item("CoBrokePhone").ToString
                    lblhidCoBrokeMobile.Text = row.Item("CoBrokeMobile").ToString
                    lblhidCoBrokeFax.Text = row.Item("CoBrokeFax").ToString
                    lblhidCoBrokeEmail.Text = row.Item("CoBrokeEmail").ToString
                Else
                    CoBroke.Visible = False
                End If
                lblTransactDate.Text = Format(row.Item("TransactDate"), "dd-MMM-yyyy")
                lblRemark.Text = row.Item("TransactRemark").ToString
                lblMonthlyRental.Text = String.Format("{0:#,##0.00}", row.Item("MonthlyRental"))
                lblRequisition.Text = row.Item("Requisition").ToString
                'lblTransactor.Text = row.Item("Transactor").ToString
                lblTransactor.Text = row.Item("TransactorInitial").ToString
                lblhidTransactorId.Text = row.Item("TransactorId").ToString
                'lblLister.Text = row.Item("Lister").ToString
                lblLister.Text = row.Item("ListerInitial").ToString
                lblhidListerId.Text = row.Item("ListerId").ToString
                lblTerminationClause.Text = row.Item("TerminationClause").ToString
                If row.Item("SignComplete").ToString = "1" Then
                    lblPendingSigning.Text = "Signed"
                    If row.Item("SignDate").ToString = "" Then
                        txtSignDate.Text = ""
                    Else
                        txtSignDate.Text = Format(row.Item("SignDate"), "dd-MMM-yyyy")
                    End If
                    If row.Item("CommencementDate").ToString = "" Then
                        txtCommencementDate.Text = ""
                    Else
                        txtCommencementDate.Text = Format(row.Item("CommencementDate"), "dd-MMM-yyyy")
                    End If
                    txtRentFreePeriod.Text = row.Item("RentFreePeriod").ToString
                    ddlRentFreePeriodType.SelectedValue = row.Item("RentFreePeriodType").ToString
                    txtSignRemark.Text = row.Item("SignRemark").ToString
                    chkSignComplete.Checked = True
                    txtSignDate.Enabled = False
                    txtSignRemark.Enabled = False
                    chkSignComplete.Enabled = False
                    txtCommencementDate.Enabled = False
                    txtRentFreePeriod.Enabled = False
                    ddlRentFreePeriodType.Enabled = False
                    imgSignDateCal.Enabled = False
                    imgCommencementDateCal.Enabled = False
                    If row.Item("SignCompleteDate").ToString = "" Then
                        lblSignRemark.Text = ""
                    Else
                        'lblSignRemark.Text = row.Item("SignCompleteBy").ToString & " on " & Format(row.Item("SignCompleteDate"), "dd-MMM-yyyy")
                        lblSignRemark.Text = row.Item("SignCompleteByInitial").ToString & " on " & Format(row.Item("SignCompleteDate"), "dd-MMM-yyyy")
                    End If
                Else
                    If row.Item("SignDate").ToString = "" Then
                        txtSignDate.Text = ""
                    Else
                        txtSignDate.Text = Format(row.Item("SignDate"), "dd-MMM-yyyy")
                    End If
                    If row.Item("CommencementDate").ToString = "" Then
                        txtCommencementDate.Text = ""
                    Else
                        txtCommencementDate.Text = Format(row.Item("CommencementDate"), "dd-MMM-yyyy")
                    End If
                    txtRentFreePeriod.Text = row.Item("RentFreePeriod").ToString
                    ddlRentFreePeriodType.SelectedValue = row.Item("RentFreePeriodType").ToString
                    txtSignRemark.Text = row.Item("SignRemark").ToString
                    chkSignComplete.Checked = False
                    txtSignDate.Enabled = True
                    txtSignRemark.Enabled = True
                    chkSignComplete.Enabled = True
                    txtCommencementDate.Enabled = True
                    txtRentFreePeriod.Enabled = True
                    ddlRentFreePeriodType.Enabled = True
                    imgSignDateCal.Enabled = True
                    imgCommencementDateCal.Enabled = True
                End If
                If row.Item("CollectComplete").ToString = "1" Then
                    lblPendingCollection.Text = "Collected"
                    If row.Item("CollectDate").ToString = "" Then
                        txtCollectDate.Text = ""
                    Else
                        txtCollectDate.Text = Format(row.Item("CollectDate"), "dd-MMM-yyyy")
                    End If
                    txtCollectRemark.Text = row.Item("CollectRemark").ToString
                    txtCollectAmt.Text = String.Format("{0:#,##0.00}", row.Item("CollectAmt"))
                    chkCollectComplete.Checked = True
                    txtCollectDate.Enabled = False
                    txtCollectRemark.Enabled = False
                    txtCollectAmt.Enabled = False
                    chkCollectComplete.Enabled = False
                    If row.Item("CollectCompleteDate").ToString = "" Then
                        lblCollectRemark.Text = ""
                    Else
                        'lblCollectRemark.Text = row.Item("CollectCompleteBy").ToString & " on " & Format(row.Item("CollectCompleteDate"), "dd-MMM-yyyy")
                        lblCollectRemark.Text = row.Item("CollectCompleteByInitial").ToString & " on " & Format(row.Item("CollectCompleteDate"), "dd-MMM-yyyy")
                    End If
                Else
                    If row.Item("CollectDate").ToString = "" Then
                        txtCollectDate.Text = ""
                    Else
                        txtCollectDate.Text = Format(row.Item("CollectDate"), "dd-MMM-yyyy")
                    End If
                    txtCollectRemark.Text = row.Item("CollectRemark").ToString
                    txtCollectAmt.Text = String.Format("{0:#,##0.00}", row.Item("CollectAmt"))
                    chkCollectComplete.Checked = False
                    txtCollectDate.Enabled = True
                    txtCollectRemark.Enabled = True
                    txtCollectAmt.Enabled = True
                    chkCollectComplete.Enabled = True
                End If
                'txtLandlordAgencyFee.Text = row.Item("AgencyFee").ToString
                'txtLandlordReferralAmt.Text = row.Item("LandlordReferralAmtSum").ToString
                'txtLandlordGst.Text = row.Item("GST").ToString
                'If row.Item("GSTPaidBy").ToString = "1" Then
                '    chkLandlordGstPaid.Checked = True
                'Else
                '    chkLandlordGstPaid.Checked = False
                'End If
                lblListingPercent.Text = row.Item("ListingPercent").ToString
                lblListingFee.Text = "0.00"

                'edited by Tan Chin Teong on 20120618
                'delete the stamp duty instead of plus stamp duty.
                If row.Item("GSTPaidBy").ToString = "1" Then
                    lblhidAmountToCollect.Text = String.Format("{0:#,##0.00}", (CDbl(row.Item("TotalAgencyFee").ToString) + CDbl(row.Item("GovAmt").ToString) + CDbl(row.Item("TotalTA").ToString) - CDbl(row.Item("StampDuty").ToString)))
                Else
                    lblhidAmountToCollect.Text = String.Format("{0:#,##0.00}", (CDbl(row.Item("TotalAgencyFee").ToString) + CDbl(row.Item("TotalTA").ToString) - CDbl(row.Item("StampDuty").ToString)))
                End If
                If chkSignComplete.Checked Then
                    pnlCollection.Visible = True
                Else
                    pnlCollection.Visible = True    'Edit by Tan Chin Teong 20120429 - show pending & collection together
                End If
            End If
        Next
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        If chkCollectComplete.Checked Then
            If CDbl(txtCollectAmt.Text) <> CDbl(lblhidAmountToCollect.Text) Then
                lblMsgError.Text = "Error. You can't proceed as the collected amount not correct!"
                divError.Visible = True
                chkCollectComplete.Checked = False
                Exit Sub
            End If
        End If
        Dim blnUpdatePropertyStatus As Boolean = False
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            Dim strOpenFileFormat As String = ""
            Dim bolCloseUseOpen As Boolean = False
            Dim bolInvoiceUseOpen As Boolean = False
            Dim bolInvoiceUseClose As Boolean = False
            Dim TempDt As New Data.DataTable
            'Added by : Daniel Lee
            'Date : 20-July-2011
            'Purpose : To Check option to refer open or close file number for both Close Format and Invoice Format
            objDB.dbVariable.SQLString = "SELECT OpenFileRef FROM AW_RentTransaction WHERE TransactionId=@TransactionId"
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
            objDB.FillData(TempDt, "OpenFileRef", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In TempDt.Rows
                strOpenFileFormat = ReadRow.Item("OpenFileRef").ToString
            Next

            TempDt = New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT CloseUseOpen,InvoiceUseClose,InvoiceUseOpen FROM AW_Setting"
            objDB.FillData(TempDt, "Setting", Database.SQLCommandType.NormalString)

            For Each ReadRow As Data.DataRow In TempDt.Rows
                If ReadRow.Item("CloseUseOpen") = 1 Then
                    bolCloseUseOpen = True
                Else
                    bolCloseUseOpen = False
                End If

                If ReadRow.Item("InvoiceUseClose") = 1 Then
                    bolInvoiceUseClose = True
                Else
                    bolInvoiceUseClose = False
                End If

                If ReadRow.Item("InvoiceUseOpen") = 1 Then
                    bolInvoiceUseOpen = True
                Else
                    bolInvoiceUseOpen = False
                End If
            Next

            objDB.ClearParameter()
            'End Check for Reference
            objDB.OpenConnection()
            objDB.InitDbTrans()
            If chkSignComplete.Checked = True And chkCollectComplete.Checked = False Then
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 2)
                objDB.AddParameter("CloseFileRef", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("InvoiceNumbeR", Data.SqlDbType.NVarChar, DBNull.Value)
                blnUpdatePropertyStatus = False
            ElseIf chkSignComplete.Checked = False And chkCollectComplete.Checked = True Then   'Edit by Tan Chin Teong 20120429 to make sure collection and pending appear together
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("CloseFileRef", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("InvoiceNumbeR", Data.SqlDbType.NVarChar, DBNull.Value)
                blnUpdatePropertyStatus = False
            ElseIf chkSignComplete.Checked = True And chkCollectComplete.Checked = True Then
                Dim strCloseFileRef As String = String.Empty
                Dim strInvoiceFileRef As String = String.Empty
                'Changed by : Daniel Lee
                'Date : 20-July-2011
                'Purpose : To Check option to refer open or close file number for both Close Format and Invoice Format
                If bolCloseUseOpen = True Then
                    strCloseFileRef = strOpenFileFormat
                Else
                    getCloseFormatNumber(objDB, strCloseFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerId.Text.Trim), "R", New Guid(lblStaffUID.Text))
                End If

                If bolInvoiceUseClose = True Then
                    strInvoiceFileRef = strCloseFileRef
                ElseIf bolInvoiceUseOpen = True Then
                    strInvoiceFileRef = strOpenFileFormat
                Else
                    getInvoiceFormatNumber(objDB, strInvoiceFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerId.Text.Trim), "R", New Guid(lblStaffUID.Text))
                End If
                'getCloseFormatNumber(objDB, strCloseFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerId.Text.Trim), "R", New Guid(lblStaffUID.Text))
                'getInvoiceFormatNumber(objDB, strInvoiceFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerId.Text.Trim), "R", New Guid(lblStaffUID.Text))
                objDB.AddParameter("CloseFileRef", Data.SqlDbType.NVarChar, strCloseFileRef)
                objDB.AddParameter("InvoiceNumbeR", Data.SqlDbType.NVarChar, strInvoiceFileRef)
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 3)
                blnUpdatePropertyStatus = True
            Else
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("CloseFileRef", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("InvoiceNumbeR", Data.SqlDbType.NVarChar, DBNull.Value)
                blnUpdatePropertyStatus = False
            End If
            objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET " & _
                                        "SignDate=@SignDate, SignRemark=@SignRemark, SignComplete=@SignComplete, CollectDate=@CollectDate, " & _
                                        "CollectAmt=@CollectAmt, CollectRemark=@CollectRemark, UpdateDate=@UpdateDate, UpdateWho=@UpdateWho, " & _
                                        "CollectComplete=@CollectComplete, Status=@Status, CommencementDate=@CommencementDate, " & _
                                        "RentFreePeriod=@RentFreePeriod, RentFreePeriodType=@RentFreePeriodType, " & _
                                        "SignCompleteBy=@SignCompleteBy, SignCompleteDate=@SignCompleteDate, CollectCompleteBy=@CollectCompleteBy, " & _
                                        "CollectCompleteDate=@CollectCompleteDate, CloseFileRef=@CloseFileRef, InvoiceNumber=@InvoiceNumber WHERE TransactionId=@TransId"
            If txtSignDate.Text = "" Then
                objDB.AddParameter("SignDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("SignDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtSignDate.Text, "dd-MMM-yyyy", Nothing))
            End If
            If txtSignRemark.Text = "" Then
                objDB.AddParameter("SignRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("SignRemark", Data.SqlDbType.NVarChar, txtSignRemark.Text.Trim)
            End If
            If chkSignComplete.Checked = True Then
                objDB.AddParameter("SignComplete", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("SignCompleteBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
                objDB.AddParameter("SignCompleteDate", Data.SqlDbType.DateTime, Now())
            Else
                objDB.AddParameter("SignComplete", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("SignCompleteBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("SignCompleteDate", Data.SqlDbType.DateTime, DBNull.Value)
            End If
            If txtCommencementDate.Text = "" Then
                objDB.AddParameter("CommencementDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("CommencementDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtCommencementDate.Text, "dd-MMM-yyyy", Nothing))
            End If
            If txtRentFreePeriod.Text = "" Then
                objDB.AddParameter("RentFreePeriod", Data.SqlDbType.Int, DBNull.Value)
            Else
                objDB.AddParameter("RentFreePeriod", Data.SqlDbType.Int, CInt(txtRentFreePeriod.Text.Trim))
            End If
            objDB.AddParameter("RentFreePeriodType", Data.SqlDbType.TinyInt, CInt(ddlRentFreePeriodType.SelectedValue))
            If txtCollectDate.Text = "" Then
                objDB.AddParameter("CollectDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("CollectDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtCollectDate.Text, "dd-MMM-yyyy", Nothing))
            End If
            If txtCollectAmt.Text = "" Then
                objDB.AddParameter("CollectAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("CollectAmt", Data.SqlDbType.Decimal, CDbl(txtCollectAmt.Text.Trim))
            End If
            If txtCollectRemark.Text = "" Then
                objDB.AddParameter("CollectRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("CollectRemark", Data.SqlDbType.NVarChar, txtCollectRemark.Text.Trim)
            End If
            If chkCollectComplete.Checked = True Then
                objDB.AddParameter("CollectComplete", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("CollectCompleteBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
                objDB.AddParameter("CollectCompleteDate", Data.SqlDbType.DateTime, Now())
                'blnUpdatePropertyStatus = True
            Else
                objDB.AddParameter("CollectComplete", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("CollectCompleteBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
                objDB.AddParameter("CollectCompleteDate", Data.SqlDbType.DateTime, DBNull.Value)
                'blnUpdatePropertyStatus = False
            End If
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
            objDB.ExecuteQuery(False)
            InsertTrans_Old("UPDATE", objDB)
            If blnUpdatePropertyStatus Then
                UpdatePropertyStatus(objDB)
            End If
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Session.Add("entrystatus", lblAddress.Text.Trim)
            Response.Redirect("Translist.aspx", False)
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
    End Sub

    Private Sub UpdatePropertyStatus(ByRef objDB As Database)
        objDB.ClearParameter()
        objDB.dbVariable.SQLString = "UPDATE AW_Property SET RRelistStatus=@SRelistStatus " & _
                                    "WHERE PropertyId=@PropertyId"
        objDB.AddParameter("SRelistStatus", Data.SqlDbType.TinyInt, 2)
        'objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
        'objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("PropertyId", Data.SqlDbType.UniqueIdentifier, New Guid(lblPropertyUID.Text.Trim))
        objDB.ExecuteQuery()
        InsertIntoProperty_Old(2, lblPropertyUID.Text.Trim, objDB)
    End Sub

    Protected Sub BtnAbortTransaction_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAbortTransaction.Click
        pnlUndoTrans.Visible = True
        lblUndoDate.Text = Now.ToString("dd-MMM-yyyy")
        'Signing
        txtSignDate.Enabled = False
        txtSignRemark.Enabled = False
        txtCommencementDate.Enabled = False
        txtRentFreePeriod.Enabled = False
        ddlRentFreePeriodType.Enabled = False
        chkSignComplete.Enabled = False
        imgSignDateCal.Enabled = False
        imgCommencementDateCal.Enabled = False
        'Collection
        txtCollectDate.Enabled = False
        txtCollectRemark.Enabled = False
        txtCollectAmt.Enabled = False
        chkCollectComplete.Enabled = False
        imgCollectDateCal.Enabled = False
        'Hide Unnecessary row first
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkUndoInfo", "checkUndoInfo();", True)
        'hide the button
        BtnAbortTransaction.Visible = False
        btnBack.Visible = False
        BtnSave.Visible = False
    End Sub

    Protected Sub btnAbort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAbort.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            Dim GrossAmount As Decimal
            If CDbl(txtUndoCollectAmt.Text) = 0 Then
                GrossAmount = 0
            Else
                If chkLandlordGstPaid.Checked Then
                    'Gross Amt
                    GrossAmount = Format(CDbl(txtLandlordAgencyFee.Text) + (CDbl(txtLandlordAgencyFee.Text) * (CDbl(txtLandlordGst.Text) / 100)), "0.00")
                Else
                    'Gross Amt
                    GrossAmount = Format(CDbl(txtLandlordAgencyFee.Text), "0.00")
                End If
            End If
            If GrossAmount <> CDbl(txtUndoCollectAmt.Text) Then
                lblMsgError.Text = "Error. You can't proceed as the collected amount not correct!"
                divError.Visible = True
                Exit Sub
            End If
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.dbVariable.SQLString = "UPDATE AW_RentTransaction SET " & _
                                        "UndoDate=@UndoDate, UndoRemark=@UndoRemark, UndoAmt=@UndoAmt, UpdateDate=@UpdateDate, " & _
                                        "UndoBy=@UndoBy, UndoAgencyFee=@UndoAgencyFee, UndoGST=@UndoGST, UndoGSTPaidBy=@UndoGSTPaidBy, " & _
                                        "UndoListerAmt=@UndoListerAmt, UpdateWho=@UpdateWho, Status=@Status WHERE TransactionId=@TransId"
            objDB.AddParameter("UndoDate", Data.SqlDbType.DateTime, DateTime.ParseExact(lblUndoDate.Text, "dd-MMM-yyyy", Nothing))
            If txtRemark.Text = "" Then
                objDB.AddParameter("UndoRemark", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("UndoRemark", Data.SqlDbType.NVarChar, txtRemark.Text.Trim)
            End If
            If txtUndoCollectAmt.Text = "" Then
                objDB.AddParameter("UndoAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("UndoAmt", Data.SqlDbType.Decimal, CDbl(txtUndoCollectAmt.Text.Trim))
            End If
            If CDbl(txtUndoCollectAmt.Text) > 0 Then
                objDB.AddParameter("UndoAgencyFee", Data.SqlDbType.Decimal, CDbl(txtLandlordAgencyFee.Text.Trim))
                objDB.AddParameter("UndoGST", Data.SqlDbType.Decimal, CDbl(txtLandlordGst.Text.Trim))
                If chkLandlordGstPaid.Checked Then
                    objDB.AddParameter("UndoGSTPaidBy", Data.SqlDbType.TinyInt, 1)
                Else
                    objDB.AddParameter("UndoGSTPaidBy", Data.SqlDbType.TinyInt, 0)
                End If
                objDB.AddParameter("UndoListerAmt", Data.SqlDbType.Decimal, CDbl(lblListingFee.Text.Trim))
            Else
                objDB.AddParameter("UndoAgencyFee", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("UndoGST", Data.SqlDbType.Decimal, DBNull.Value)
                objDB.AddParameter("UndoGSTPaidBy", Data.SqlDbType.TinyInt, DBNull.Value)
                objDB.AddParameter("UndoListerAmt", Data.SqlDbType.Decimal, DBNull.Value)
            End If
            objDB.AddParameter("UndoBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 3)
            objDB.ExecuteQuery(False)
            InsertTrans_Old("ABORT", objDB)
            UpdatePropertyStatus(objDB)
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Session.Add("entrystatus", lblAddress.Text.Trim)
            Response.Redirect("Translist.aspx", False)
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
    End Sub

    Protected Sub btnCancelAbort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancelAbort.Click
        pnlUndoTrans.Visible = False
        'Signing
        If chkSignComplete.Checked Then
            txtSignDate.Enabled = False
            txtSignRemark.Enabled = False
            txtCommencementDate.Enabled = False
            txtRentFreePeriod.Enabled = False
            ddlRentFreePeriodType.Enabled = False
            chkSignComplete.Enabled = False
            imgSignDateCal.Enabled = False
            imgCommencementDateCal.Enabled = False
        Else
            txtSignDate.Enabled = True
            txtSignRemark.Enabled = True
            txtCommencementDate.Enabled = True
            txtRentFreePeriod.Enabled = True
            ddlRentFreePeriodType.Enabled = True
            chkSignComplete.Enabled = True
            imgSignDateCal.Enabled = True
            imgCommencementDateCal.Enabled = True
        End If
      
        'Collection
        txtCollectDate.Enabled = True
        txtCollectRemark.Enabled = True
        txtCollectAmt.Enabled = True
        chkCollectComplete.Enabled = True
        imgCollectDateCal.Enabled = True


        'unhide the button
        BtnAbortTransaction.Visible = True
        btnBack.Visible = True
        BtnSave.Visible = True
    End Sub

    ''' <summary>
    ''' This function will Get All the Formatted Number
    ''' </summary>
    ''' <param name="ObjDB">The Database object used</param>
    ''' <param name="CloseFormat">This will return the Format Number just Pass a Variable</param>
    ''' <param name="TransactorUid">The GUID variable of the Transactor</param>
    ''' <param name="ListerUid">The GUID variable of the Lister</param>
    ''' <param name="ListType">Please pass in only R or S</param>
    ''' <returns>It Returns nothing but it uses the ByRef</returns>
    ''' <remarks></remarks>
    Private Function getCloseFormatNumber(ByRef ObjDB As Database, ByRef CloseFormat As String, ByVal TransactorUid As Guid, ByVal ListerUid As Guid, ByVal ListType As String, ByVal LoginUid As Guid) As Integer

        Dim InvoiceDT As New Data.DataTable
        Dim ListerDT As New Data.DataTable
        Dim TransactorDT As New Data.DataTable
        Dim RunningNoDt As New Data.DataTable
        Dim CloseFileRunningNo As Integer = 0
        Dim TransactorInitial As String = ""
        Dim ListerInitial As String = ""
        Dim ListerName As String = ""
        Dim CompanyName As String = ""
        Dim CompanyInitial As String = ""
        'Added by : Daniel
        'Date : 19-July-2011
        'Purpose : To include Login Id
        Dim LoginInitialDT As New Data.DataTable
        Dim LoginInital As String = ""

        'Get All Information Before Proceesing
        'Get Transactor Initial
        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, TransactorUid)
        ObjDB.FillData(TransactorDT, "Transactor", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In TransactorDT.Rows
            TransactorInitial = ReadRow.Item("Initial").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, LoginUid)
        ObjDB.FillData(LoginInitialDT, "LoginInitial", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In LoginInitialDT.Rows
            LoginInital = ReadRow.Item("Initial").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT Initial,Name FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, ListerUid)
        ObjDB.FillData(ListerDT, "Lister", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListerDT.Rows
            ListerInitial = ReadRow.Item("Initial").ToString
            ListerName = ReadRow.Item("Name").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT CurrentNo,RunType FROM aw_runningNo WITH (TABLOCKX) WHERE RunType='C' "
        ObjDB.FillData(RunningNoDt, "RunningNo", Database.SQLCommandType.NormalString)

        'Begin Updating Current Running No
        ObjDB.dbVariable.SQLString = "UPDATE aw_runningNo SET CurrentNo=CurrentNo+1 WHERE RunType='C'"
        ObjDB.ExecuteQuery()

        For Each ReadRow As Data.DataRow In RunningNoDt.Rows
            If ReadRow.Item("RunType").ToString = "C" Then
                CloseFileRunningNo = ReadRow.Item("CurrentNo")
            End If
        Next

        ObjDB.dbVariable.SQLString = "SELECT CloseFormat,CompanyName,CompanyInitial FROM AW_Setting"
        ObjDB.FillData(InvoiceDT, "CloseFormat", Database.SQLCommandType.NormalString)

        Dim CloseFormatString As String()

        For Each ReadRow As Data.DataRow In InvoiceDT.Rows
            CloseFormatString = ReadRow.Item("CloseFormat").ToString.Split(";")
            CompanyInitial = ReadRow.Item("CompanyInitial").ToString
            CompanyName = ReadRow.Item("CompanyName").ToString
        Next


        Dim strCloseFormat As String = String.Empty
        If CloseFormatString.Count > 0 Then
            For Each Format As String In CloseFormatString
                Select Case Format.Trim
                    Case "tInit"
                        strCloseFormat = strCloseFormat & TransactorInitial
                    Case "lName"
                        strCloseFormat = strCloseFormat & ListerName
                    Case "lInit"
                        strCloseFormat = strCloseFormat & ListerInitial
                    Case "cName"
                        strCloseFormat = strCloseFormat & CompanyName
                    Case "cInit"
                        strCloseFormat = strCloseFormat & CompanyInitial
                    Case "rNumber"
                        strCloseFormat = strCloseFormat & CloseFileRunningNo
                    Case "dDate1"
                        strCloseFormat = strCloseFormat & Now.ToString("dd/MM")
                    Case "dDate2"
                        strCloseFormat = strCloseFormat & Now.ToString("dd/MM/yyyy")
                    Case "LoginInit"
                        strCloseFormat = strCloseFormat & LoginInital
                    Case "lType"
                        If ListType = "S" Then
                            strCloseFormat = strCloseFormat & "S"
                        Else
                            strCloseFormat = strCloseFormat & "R"
                        End If
                    Case "dash"
                        strCloseFormat = strCloseFormat & "-"
                    Case "slash"
                        strCloseFormat = strCloseFormat & "/"
                    Case "empty"
                        strCloseFormat = strCloseFormat & ""
                End Select

            Next
        End If

        CloseFormat = strCloseFormat
        Return 0
    End Function

    ''' <summary>
    ''' This function will Get All the Formatted Number
    ''' </summary>
    ''' <param name="ObjDB">The Database object used</param>
    ''' <param name="InvoiceFormat">This will return the Format Number just Pass a Variable</param>
    ''' <param name="TransactorUid">The GUID variable of the Transactor</param>
    ''' <param name="ListerUid">The GUID variable of the Lister</param>
    ''' <param name="ListType">Please pass in only R or S</param>
    ''' <returns>It Returns nothing but it uses the ByRef</returns>
    ''' <remarks></remarks>
    Private Function getInvoiceFormatNumber(ByRef ObjDB As Database, ByRef InvoiceFormat As String, ByVal TransactorUid As Guid, ByVal ListerUid As Guid, ByVal ListType As String, ByVal LoginUid As Guid) As Integer

        Dim InvoiceDT As New Data.DataTable
        Dim ListerDT As New Data.DataTable
        Dim TransactorDT As New Data.DataTable
        Dim RunningNoDt As New Data.DataTable
        Dim InvoiceRunningNo As Integer = 0
        Dim TransactorInitial As String = ""
        Dim ListerInitial As String = ""
        Dim ListerName As String = ""
        Dim CompanyName As String = ""
        Dim CompanyInitial As String = ""
        'Added by : Daniel
        'Date : 19-July-2011
        'Purpose : To include Login Id
        Dim LoginInitialDT As New Data.DataTable
        Dim LoginInital As String = ""


        'Get All Information Before Proceesing
        'Get Transactor Initial
        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, TransactorUid)
        ObjDB.FillData(TransactorDT, "Transactor", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In TransactorDT.Rows
            TransactorInitial = ReadRow.Item("Initial").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, LoginUid)
        ObjDB.FillData(LoginInitialDT, "LoginInitial", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In LoginInitialDT.Rows
            LoginInital = ReadRow.Item("Initial").ToString
        Next


        ObjDB.dbVariable.SQLString = "SELECT Initial,Name FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, ListerUid)
        ObjDB.FillData(ListerDT, "Lister", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListerDT.Rows
            ListerInitial = ReadRow.Item("Initial").ToString
            ListerName = ReadRow.Item("Name").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT CurrentNo,RunType FROM aw_runningNo WITH (TABLOCKX) WHERE RunType='I' "
        ObjDB.FillData(RunningNoDt, "RunningNo", Database.SQLCommandType.NormalString)

        'Begin Updating Current Running No
        ObjDB.dbVariable.SQLString = "UPDATE aw_runningNo SET CurrentNo=CurrentNo+1 WHERE RunType='I'"
        ObjDB.ExecuteQuery()

        For Each ReadRow As Data.DataRow In RunningNoDt.Rows
            If ReadRow.Item("RunType").ToString = "I" Then
                InvoiceRunningNo = ReadRow.Item("CurrentNo")
            End If
        Next

        ObjDB.dbVariable.SQLString = "SELECT InvoiceFormat,CompanyName,CompanyInitial FROM AW_Setting"
        ObjDB.FillData(InvoiceDT, "CloseFormat", Database.SQLCommandType.NormalString)

        Dim InvoiceFormatString As String()

        For Each ReadRow As Data.DataRow In InvoiceDT.Rows
            InvoiceFormatString = ReadRow.Item("InvoiceFormat").ToString.Split(";")
            CompanyInitial = ReadRow.Item("CompanyInitial").ToString
            CompanyName = ReadRow.Item("CompanyName").ToString
        Next


        Dim strInvoiceFormat As String = String.Empty
        If InvoiceFormatString.Count > 0 Then
            For Each Format As String In InvoiceFormatString
                Select Case Format.Trim
                    Case "tInit"
                        strInvoiceFormat = strInvoiceFormat & TransactorInitial
                    Case "lName"
                        strInvoiceFormat = strInvoiceFormat & ListerName
                    Case "lInit"
                        strInvoiceFormat = strInvoiceFormat & ListerInitial
                    Case "cName"
                        strInvoiceFormat = strInvoiceFormat & CompanyName
                    Case "cInit"
                        strInvoiceFormat = strInvoiceFormat & CompanyInitial
                    Case "rNumber"
                        strInvoiceFormat = strInvoiceFormat & strInvoiceFormat
                    Case "dDate1"
                        strInvoiceFormat = strInvoiceFormat & Now.ToString("dd/MM")
                    Case "dDate2"
                        strInvoiceFormat = strInvoiceFormat & Now.ToString("dd/MM/yyyy")
                    Case "LoginInit"
                        strInvoiceFormat = strInvoiceFormat & LoginInital
                    Case "lType"
                        If ListType = "S" Then
                            strInvoiceFormat = strInvoiceFormat & "S"
                        Else
                            strInvoiceFormat = strInvoiceFormat & "R"
                        End If
                    Case "dash"
                        strInvoiceFormat = strInvoiceFormat & "-"
                    Case "slash"
                        strInvoiceFormat = strInvoiceFormat & "/"
                    Case "empty"
                        strInvoiceFormat = strInvoiceFormat & ""
                End Select

            Next
        End If

        InvoiceFormat = strInvoiceFormat
        Return 0
    End Function

    Private Sub InsertIntoProperty_Old(ByVal RelistStatus As String, ByVal PropertyUID As String, ByVal objdb As Database)
        Dim strRelistStatus As String

        If RelistStatus = "" Then
            objdb.AddParameter("RelistStatusOLD", Data.SqlDbType.TinyInt, DBNull.Value)
        Else
            objdb.AddParameter("RelistStatusOLD", Data.SqlDbType.TinyInt, RelistStatus)
        End If

        strRelistStatus = " SRelistStatus, @RelistStatusOLD,"

        objdb.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_Property " & _
            "(OId, PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, STransactionId, RTransactionId, SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, SListStatus, RListStatus, SRelistStatus, RRelistStatus, CreateDate, StatusDelete, UpdateDate, UpdateWho, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister) " & _
            "SELECT @OId, PropertyId, RoadId, ProjectId, PropertyTypeId, UnitNumber, ListType, STransactionId, RTransactionId, SRAmt, " & _
            "SRPSF, SRAskAmt, SRAskPSF, SRCreateDate, SRYes, SCAmt, SCPSF, SCAskAmt, SCAskPSF, SCCreateDate, SCYes, SLAmt, " & _
            "SLPSF, SLAskAmt, SLAskPSF, SLCreateDate, SLYes, SIAmt, SIPSF, SIAskAmt, SIAskPSF, SICreateDate, SIYes, RRAmt, " & _
            "RRPSF, RRAskAmt, RRAskPSF, RRCreateDate, RRYes, RCAmt, RCPSF, RCAskAmt, RCAskPSF, RCCreateDate, RCYes, RLAmt, " & _
            "RLPSF, RLAskAmt, RLAskPSF, RLCreateDate, RLYes, RIAmt, RIPSF, RIAskAmt, RIAskPSF, RICreateDate, RIYes, " & _
            "SListerId, RListerId, KeyInOffice, ProjectRemark, PropertyDesc, SignboardStatus, SignboardWhere, SignboardWhen, " & _
            "SurveySheet, QuitRent, AssessmentBill, PendingStatus, PendingWho, PendingWhen, PendingWhy, Tenure, ListHoldExpired, " & _
            "Access, AccessRemark, Condition, ConditionRemark, Facing, Zoning, ZoningRemark, Room, Bathroom, BestBuy, ExclusiveStatus, ExclusiveWho, ExclusiveWhen, ExclusiveEndDate, " & _
            "AuthorizeSaleRent, Remark, Production1, Production2, Production3, Admin1, Admin2, Admin3, LAWidth, LALength, " & _
            "LASF, BUWidth, BULength, BUSF, FloorLoad, SECMK, Ceiling, Terrain, District, Lot, Phase, Furnished, FurnishedRemark, " & _
            "Renovated, RenovatedRemark, Developer, OwnerName, OwnerMobile, OwnerPhone, OwnerFax, OwnerEmail, " & _
            "OwnerAddress, ReferLister, SListStatus, RListstatus, " & strRelistStatus & "@CreateDateOLD, StatusDelete, @UpdateDateOLD, @UpdateWhoOLD, " & _
            "LandlordName, LandlordMobile, LandlordPhone, LandlordFax, LandlordEmail, LandlordAddress, ReferLandlordLister " & _
            "FROM AW_Property WHERE PropertyId = @PropertyIdOLD"
        objdb.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        objdb.AddParameter("PropertyIdOLD", Data.SqlDbType.UniqueIdentifier, New Guid(PropertyUID))
        objdb.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objdb.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objdb.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objdb.ExecuteQuery(False)

    End Sub

    Private Sub InsertTrans_Old(ByVal TType As String, ByVal objDB As Database)

        If TType = "ABORT" Then 'Abort
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                        "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                        "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                        "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                        "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                        "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                        "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                        "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                        "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                        "TerminationClause, PremiseUse, CreateDate, UpdateDate, UpdateWho, Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                        "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                        "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                        "UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                        "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                        "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                        "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                        "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                        "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                        "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                        "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                        "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                        "TerminationClause, PremiseUse, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, @Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                        "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                        "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, @UndoDate, @UndoRemark, @UndoAmt, @UndoBy, @UndoAgencyFee, " & _
                        "@UndoGST, @UndoGSTPaidBy, @UndoListerAmt FROM AW_RentTransaction WHERE TransactionId=@TransId"
        Else 'Update Status
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_RentTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, CloseFileRef, ListerId, ListDate, " & _
                                   "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                                   "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                                   "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                                   "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                                   "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                                   "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                                   "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                                   "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                                   "TerminationClause, PremiseUse, CreateDate, UpdateDate, UpdateWho, Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                                   "GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, SignCompleteDate, CommencementDate, RentFreePeriod, RentFreePeriodType, " & _
                                   "CollectDate, CollectAmt, CollectRemark, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                                   "UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, @InvoiceNumber, OpenFileRef, @CloseFileRef, ListerId, ListDate, " & _
                                   "LandlordType, LandlordName1, LandlordName2, LandlordName3, LandlordCompany, LandlordNRIC1, LandlordNRIC2, LandlordNRIC3, LandlordCompanyNo, " & _
                                   "LandlordContactPerson, LandlordAddress, LandlordPhone, LandlordMobile, LandlordFax, LandlordEmail, LandlordViewMeetTele, LandlordIncomeTax, " & _
                                   "LandlordReferral, LandlordReferralName, LandlordReferralNRIC, LandlordReferralContact, LandlordReferralStatus, LandlordReferralAmount, " & _
                                   "LandlordReferralAmtSum, AgencyFee, GST, GSTPaidBy, ListingFee, LandlordTAFee, TenantType, TenantName1, TenantName2, TenantName3, TenantCompany, " & _
                                   "TenantNRIC1, TenantNRIC2, TenantNRIC3, TenantCompanyNo, TenantContactPerson, TenantAddress, TenantPhone, TenantMobile, TenantFax, TenantEmail, " & _
                                   "TenantViewMeetTele, TenantIncomeTax, TenantReferral, TenantReferralName, TenantReferralNRIC, TenantReferralContact, TenantReferralStatus, " & _
                                   "TenantReferralAmount, TenantReferralAmtSum, DisbursementFee, Deposit, DepositMonth, Advance, AdvanceMonth, WaterElectric, Tel, TenantTAFee, " & _
                                   "TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, TransListType, MonthlyRental, TenancyDuration, TenancyDurationType, Requisition, " & _
                                   "TerminationClause, PremiseUse, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, @Status, Renewed, TotalTA, TotalAgencyFee, StampDuty, ListerAmt, ReferralAmt, " & _
                                   "GovAmt, GrossAmount, @SignDate, @SignRemark, @SignComplete, @SignCompleteBy, @SignCompleteDate, @CommencementDate, @RentFreePeriod, @RentFreePeriodType, " & _
                                   "@CollectDate, @CollectAmt, @CollectRemark, @CollectComplete, @CollectCompleteBy, @CollectCompleteDate, UndoDate, UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, " & _
                                   "UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_RentTransaction WHERE TransactionId=@TransId"
        End If
        'insert
        objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
        objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
        objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
        objDB.ExecuteQuery(False)
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub


    Protected Sub ObjectDataSource1_Inserting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Inserting
        Dim pageParams As IDictionary = e.InputParameters
        Dim ddlCollectionType As DropDownList

        ddlCollectionType = ListView1.InsertItem.FindControl("DropDownList1")
        pageParams.Item("TransactionId") = lblTransUID.Text.Trim
        pageParams.Item("CollectionType") = ddlCollectionType.SelectedValue
        pageParams.Item("transactor") = lblStaffUID.Text
        pageParams.Item("transactType") = "Rent"
    End Sub

    Protected Sub ObjectDataSource1_Deleting(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Deleting
        Dim pageParams As IDictionary = e.InputParameters
        pageParams.Item("transactType") = "Rent"
    End Sub

    Protected Sub ListView1_ItemCommand(sender As Object, e As System.Web.UI.WebControls.ListViewCommandEventArgs) Handles ListView1.ItemCommand

    End Sub

    Protected Sub ListView1_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.ListViewUpdateEventArgs) Handles ListView1.ItemUpdating

    End Sub

    Protected Sub ObjectDataSource1_Updating(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Updating
        Dim pageParams As IDictionary = e.InputParameters
        Dim ddlCollectionType As DropDownList

        ddlCollectionType = ListView1.EditItem.FindControl("DropDownList1")
        pageParams.Item("CollectionType") = ddlCollectionType.SelectedValue
        pageParams.Item("transactor") = lblStaffUID.Text
        pageParams.Item("transactType") = "Rent"
    End Sub

    Protected Sub ObjectDataSource1_Selected(sender As Object, e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Selected
        'Dim pct As Decimal = 0
        'Dim royaltyTable As DataTable
        'royaltyTable = e.ReturnValue
        'For Each royaltyrow As DataRow In royaltyTable.Rows
        '    pct = pct + Convert.ToDecimal(royaltyrow.Item("Amount"))
        'Next
        'txtCollectAmt.Text = pct.ToString("G")
    End Sub

    Protected Sub ListView1_DataBound(sender As Object, e As System.EventArgs) Handles ListView1.DataBound
        Dim pct As Decimal = 0
        Dim lblDate As Label
        lblDate = New Label
        lblDate.Text = Date.Now.ToShortDateString
        For Each lvitem As ListViewItem In ListView1.Items
            Dim lblAmt As Label = lvitem.FindControl("AmountLabel")

            If lblAmt Is Nothing = False Then
                pct = pct + Convert.ToDecimal(lblAmt.Text)
            End If

            If lvitem.FindControl("CollectdateLabel") Is Nothing = False Then
                lblDate = lvitem.FindControl("CollectdateLabel")
            End If

        Next
        txtCollectAmt.Text = pct.ToString("G")
        txtCollectDate.Text = lblDate.Text
    End Sub

End Class
